﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ScreenCaptureDemo
{
    public partial class 测试 : Form
    {
        public 测试()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        public static Bitmap CaptureScreen()
        {
            // 获取屏幕的大小
            Rectangle screenBounds = Screen.PrimaryScreen.Bounds;

            // 创建一个与屏幕大小相同的Bitmap对象
            Bitmap bitmap = new Bitmap(screenBounds.Width, screenBounds.Height);

            // 创建一个Graphics对象，并将其绑定到bitmap
            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                // 将屏幕的图像拷贝到bitmap中
                graphics.CopyFromScreen(screenBounds.Location, Point.Empty, screenBounds.Size);
            }

            return bitmap;
        }

        private async void button1_Click(object sender, EventArgs e)
        {

            for (int i = 0; i < 10000; i++)
            {
                using (Bitmap bitmap = CaptureScreen())
                {
                    if (bitmap != null)
                    {
                        this.pictureBox1.Image = bitmap;

                        await Task.Delay(1);
                    }
                }
            }



        }
    }
}
